<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>小贷账单主表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">贷款合同号</div>
                    <div class="field">
                        <input name="crCntNo" id="crCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">车贷支付表号</div>
                    <div class="field">
                        <input name="paySchId" id="paySchId" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">扣款状态</div>
                    <div class="field">
                        <select name="isSuc" id="isSuc">
                            <option value="">--全部--</option>
                            <option value="10">交易处理中</option>
                            <option value="20">交易成功</option>
                            <option value="30">交易失败</option>
                            <option value="40">未交易</option>
                            <option value="50">未交易(人工)</option>
                        </select>
                    </div>
                </div>

                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <%--<span id="picUpload" onclick="picUpload();" class="sq-button sq-button-round">批量图片上传</span>
                    <span id="huiGou" onclick="huiGou();" class="sq-button sq-button-round">回购</span>
                    <span id="pushRepaymentPlan" onclick="pushRepaymentPlan();" class="sq-button sq-button-round">推送还款计划</span>--%>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>




<script type="text/javascript">
    var grid = null, callback = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/mcr/mcrBillM/initVliList.do',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstNm+'</span></a>';
                    }
                },
                {display: '客户ID', name: 'cstId', minWidth: 180, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstId+'</span></a>';
                    }
                },
                {display: '贷款合同号', name: 'crCntNo', minWidth: 110, align: 'left',
                    render:function(rowdata,index,value){
                        return '<a href="javascript:;" style="cursor: pointer;" onclick="billDtl('+rowdata.id+')">'+rowdata.crCntNo+'</a>';
                    }
                },
                {display: '贷款金额', name: 'crAmtStr', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.actCrAmt){
                            return '&yen;'+rowdata.crAmtStr;
                        }
                    }
                },
                {display: '贷款状态', name: 'loanStsCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '创建日期', name: 'crtTm', minWidth: 150, align: 'center', enabledSort: false,render:renderDate},
                {display: '对应车贷支付表号', name: 'paySchId', minWidth: 100, align: 'center', enabledSort: false},
                {display: '对应车贷支付表期次', name: 'payCrPd', minWidth: 100, align: 'center', enabledSort: false},
                {display: '还款状态', name: 'isSuc', width: 150, enabledSort:true,
                    render:function(rowData){
                        if(rowData.isSuc=="10"){
                            return "交易处理中";
                        }else if(rowData.isSuc=="20"){
                            return "交易成功";
                        }else if(rowData.isSuc=="30"){
                            return "交易失败";
                        }else if(rowData.isSuc=="40"){
                            return "未交易";
                        }else if(rowData.isSuc=="50"){
                            return "未交易(人工)";
                        }
                    }
                },
                {display: '扣款成功时间', name: 'crtTm', minWidth: 150, align: 'center', enabledSort: false,render:renderDate},
                {display: '资金编号', name: 'fundNo', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '<a href="javascript:;" style="cursor: pointer;" onclick="showFund('+rowdata.fundId+')">'+rowdata.fundId+'</a>';
                    }
                },
                {display: '扣款失败次数', name: 'deductionNo', minWidth: 100, align: 'center', enabledSort: false},
                getGridOperColumnContent()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        //Grid操作列
        function getGridOperColumnContent(){
            var data = {
                display: '操作',
                isSort: false,
                width: 280,
                render: function (rowdata, rowindex, value){
                    var h='<a class="sq-button-hasicon" href="javascript:sendDeduction(';
                    h+="'"+rowdata.id+"'";
                    h+=",'mid_man_grid_id'"
                    h+=")\"><i class=\"sqBtnIco_4\"></i>发起查询和扣款</a>"

                    var returnStr = h;
                    if(rowdata.vliStatus == 1){
                        returnStr = h;
                    }else{
                        returnStr = "";
                    }
                    return returnStr;
                }
            }
            return data;
        }

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
            form.setData({  //重置select等特殊表单
    		    "cstNm":"",
    		    "crCntNo":""
    		  });
        });

        callback = function () {
            grid.reload();
        };

    });

    //查看账单详情
    function billDtl(billId){
        Add_navTab('MCR_BILL_M_'+billId,'小贷账单详情',"<%=path%>/mcr/mcrBillM/toBillDtlPage.do?id="+billId);
    }

    //查询客户详情
    function showCstDtl(_cstId){
        Add_navTab("MCR_BILL_M_"+_cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id='+_cstId, null);
    }

    //资金分解明细
    function showFund(id){
        Add_navTab("MCR_BILL_M_"+id, "资金分解明细", '<%=path%>/capital/capFund/toDecomDtlPage.do?fundId='+id, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //启用禁用数据
    function sendDeduction(_id){
        $.ligerDialog.confirm('手动扣款将会对客户账单进行二次扣款\n' +
            '请确认客户账单不存在扣款中状态?', function (flag) {
            if(flag == false)return;
            var url = '<%=path%>/mcr/mcrBillM/sendDeduction.do';
            AjaxUtils.ajaxPost(url, {id:_id}, delCallback);
        });
    }

    //删除回调
    function delCallback(msg){
        if(msg.success == 1){
            UIUtils.alertSuccess(msg.info);
            grid.reload();
        }else{
            UIUtils.alertError(msg.info);
        }
    }
</script>

</body>
</html>
